<?php

namespace Frieza\Modules\Position\Actions;

use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Doraemon\model\Member;

class UserRate extends RowAction
{
    public $name = '用户打分';

    public function handle($uid,Request $request)
    {
        $user_score = $request->get('user_score');
        $data['user_score'] = $user_score;
        $res = Member::updateUserInfo($uid,$data);
        if ($res){
            return $this->response()->success('用户打分操作成功!')->refresh();
        }else{
            return $this->response()->error('用户打分操作失败,稍后重试!');
        }

    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function form($request)
    {
        $uid = $request->uid;
        //获取该用户的分数
        $user_info = Member::getOne($uid);
        $user_score = $user_info['user_score'];
        $this->text('user_score', '用户搜索打分')->rules()->help('打分范围为1~~100分')->default($user_score);
    }
}
